<!-- 我的论文隐匿名评审（新版） -->
<template>
    <div>
        <div class="con color" >
            <el-row class="con_title">
              <el-col :span="6">
                <h2 class="text-style" >{{$t('paperBlindTrial.blindPaperApplyTitle')}}</h2>
                <div class="sub-text">
                  <span>{{$t('label.stuName')}}：{{global.currentUser.name}}</span>
                  <span style="margin-left: 20px;">{{$t('label.stuCode')}}：{{global.currentUser.uid}}</span>
                </div>
              </el-col>
              <el-col :span="18">
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.midCheck')}}</div>
                  <div class="left-sub" :style="thesisConcealEvaGrade.midCheck==='PASS'?'font-size: 22px;color: #67c23a;':'font-size: 22px;'">{{fieldChange(options.midCheck, thesisConcealEvaGrade.midCheck)}}</div>
                </el-col>
                <el-col :span="4" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.checkResult')}}</div>
                  <div class="left-sub" :style="this.checkResult==='PASS'?'font-size: 22px;color: #67c23a;':'font-size: 22px;'">{{fieldChange(options.checkResult, this.checkResult)}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.isDraw')}}</div>
                  <div class="left-sub" style="font-size: 22px;color: red;">{{fieldChange(options.selectedFlag, thesisConcealEvaGrade.selectedFlag)}}</div>
                </el-col>
                <el-col :span="2" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.sendCount')}}</div>
                  <div class="left-sub" style="font-size: 25px;">{{thesisConcealEvaGrade.evaCount}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.havSendArticles')}}</div>
                  <div class="left-sub" style="font-size: 25px;">{{thesisConcealEvaGrade.evaThesisCount}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.needPassNum')}}</div>
                  <div class="left-sub" style="font-size: 25px;">{{thesisConcealEvaGrade.needPassCount}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.hasPassNum')}}</div>
                  <div class="left-sub" style="font-size: 25px;">{{thesisConcealEvaGrade.passThesisCount}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.finallyResult')}}</div>
                  <div class="left-sub" :style="thesisConcealEvaGrade.finalResult==='COMPLETE'?'font-size: 22px;color: #67c23a;':'font-size: 22px;'">{{fieldChange(options.titleFinalResultArr, thesisConcealEvaGrade.finalResult)}}</div>
                </el-col>
              </el-col>
            </el-row>
            <div class="con_content">
              <el-row type="flex" justify="end">
                <el-col :span="6" style="text-align: right;margin-right: 10px;height: 50px;margin-top: 5px;">
                  <!--:disabled="manualState"-->
                  <el-button v-show="!thesisConcealEvaGrade.selectedFlag || thesisConcealEvaGrade.selectedFlag === 'UNBLIND'" class="con_apply btn_top" type="primary" @click="manualRateFunc">{{$t('paperBlindTrial.blindDraw')}}</el-button>
                  <el-button v-show="thesisConcealEvaGrade.selectedFlag === 'Y' && thesisConcealEvaGrade.finalResult === 'UNPASS'" class="con_apply btn_top" type="primary" @click="addNewApply">{{$t('paperBlindTrial.applyAgain')}}</el-button>
                  <el-button type="danger" class="con_apply btn_top"  @click="openRecheckingSystem">
                    <span style="font-size: 16px;font-weight: bold">{{$t('paperBlindTrial.recheckingSystem')}}</span>
                  </el-button>
                </el-col>
              </el-row>
                <edu-table ref="tables" :data="data" :selection="false" :total="total" @page-change="pageChange">
                    <el-table-column :min-width="item.width" v-for="item in label" :key="item.props" :label="item.label" :prop="item.props" show-overflow-tooltip></el-table-column>
                    <el-table-column min-width="80" :label="$t('paperBlindTrial.sendArticlesLabel')" prop="evaExpertCount" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{scope.row.evaExpertCount}}
                      </template>
                    </el-table-column>
                    <el-table-column min-width="80" :label="$t('paperBlindTrial.passArticles')" prop="passThesisCount" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{scope.row.passThesisCount}}
                      </template>
                    </el-table-column>
                    <el-table-column min-width="80" :label="$t('paperBlindTrial.assessResult')" prop="finalResult" fixed="right" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{ fieldChange(options.finalResultArr, scope.row.finalResult)}}
                      </template>
                    </el-table-column>
                    <el-table-column width="100px" :label="$t('nonPublicCourseOpen.operation')" fixed="right">
                        <template slot-scope="scope">
                            <div class="ReworkMana_btns" >
                              <el-button type="text" @click="add(scope.row, 'detail')">{{$t('paperBlindTrial.reviewDetail')}}</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </edu-table>
            </div>

        </div>
        <!-- 申请/查看评审详情 -->
        <el-dialog :visible.sync="dialogFlag" :title="titles" width="800px">
            <reviewDetails v-if="dialogFlag && dialogType === 'detail'" :row="rows" ref="reviewDetails" @emit:back="backFunc" type="apply"></reviewDetails>
            <span slot="footer" class="dialog-footer">
              <span v-if="dialogType === 'edit' || dialogType === 'apply'">
                <el-button @click="dialogFlag = false">{{$t('message.cancel')}}</el-button>
                <el-button type="primary" @click="sure">{{$t('message.confirm')}}</el-button>
              </span>
              <el-button v-else @click="dialogFlag = false">{{$t('common.btn.close')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { applyTableList, applyManualRate, againApply,updateApply,checkRepeat } from "common/src/api/paperBlindTrial/paperBlindTrial";
import calendars from 'common/src/api/calendars'
import reviewDetails from '../paperReviewResultNew/reviewDetails';
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import mixin from 'common/src/mixins/index';
export default {
    components: {
        reviewDetails
    },
    mixins: [commonMixins,mixin],
    props: {},
    data() {
        return {
            dialogFlag: false,
            rows: {},
            titles: this.$t('message.apply'),
            label: [
              { label: this.$t('label.schoolTerm'), props: 'yearTermI18n', width: 170 },
              { label: this.$t('achievementApply.thesisTitle'), props: 'thesisTitle', width: 150 },
              { label: this.$t('achievementApply.teacherName'), props: 'stuTutorName', width: 100 },
              { label: this.$t('paperBlindTrial.applyBatch'), props: 'batchNo', width: 100 },
              { label: this.$t('paperBlindTrial.applicantTime'), props: 'createTime', width: 155 }
            ],
            data: [],
            page: {
              pageNum_: 1,
              pageSize_: 20
            },
            total: 0,
            options: {
              applyStatus: [
                { label: this.$t('paperBlindTrial.tutorSubmit'), value: 'TUTOR_SUBMIT', type: '' },
                { label: this.$t('paperBlindTrial.blindSubmit'), value: 'BLIND_SUBMIT', type: '' },
                { label: this.$t('paperBlindTrial.tutorPass'), value: 'TUTOR_PASS', type: 'success' },
                { label: this.$t('paperBlindTrial.agreeLabel'), value: 'PASS', type: 'success' },
                { label: this.$t('achievementApply.refuse'), value: 'REJECT', type: 'danger' },
              ],
              finalResultArr: [
                { label: this.$t('message.pass'), value: 'PASS', type: 'success' },
                { label: this.$t('message.noPass'), value: 'UNPASS', type: 'danger' },
                { label: this.$t('paperBlindTrial.toBeEntered'), value: 'INCOMPLETE'},
              ],
              titleFinalResultArr: [
                { label: this.$t('message.pass'), value: 'COMPLETE', type: 'success' },
                { label: this.$t('message.pass'), value: 'PASS', type: 'success' },
                { label: this.$t('message.noPass'), value: 'UNPASS', type: 'danger' },
                { label: this.$t('achievementApply.unfinished'), value: 'INCOMPLETE'},
              ],
              evaStatus: [
                { label: this.$t('paperBlindTrial.hasSend'), value: 'Y', type: 'success' },
                { label: this.$t('paperBlindTrial.notSend'), value: 'N', type: 'warning' }
              ],
              selectedFlag: [
                { label: this.$t('paperBlindTrial.notDrawn'), value: 'UNBLIND', type: '' }, // 未抽盲
                { label: this.$t('paperBlindTrial.drawn'), value: 'Y', type: 'success' }, // 抽中
                { label: this.$t('paperBlindTrial.missed'), value: 'N', type: 'warning' } // 未中
              ],
              midCheck: [
                { label: this.$t('achievementApply.unfinished'), value: 'INCOMPLETE', type: '' }, // 未完成
                { label: this.$t('message.pass'), value: 'PASS', type: 'success' }, // 通过
              ],
              checkResult: [
                { label: this.$t('achievementApply.unfinished'), value: 1, type: 'warning' }, // 未进行查重
                { label: this.$t('achievementApply.unfinished'), value: 2, type: 'warning' }, // 查重中
                { label: this.$t('achievementApply.unfinished'), value: 3, type: 'warning' }, //查重失败
                { label: this.$t('message.pass'), value: 4, type: 'success' }, // 通过
                { label: this.$t('message.noPass'), value: 5, type: 'danger' }, // 不通过
                { label: this.$t('paperBlindTrial.checkAgainLater'), value: 6, type: 'danger' } // 查重延后
              ],
            },
            thesisConcealEvaGrade: {}, // 标题部分数据
            checkResult:1,
            yearTerms: {},
            dialogType: '',
            //manualState: true // 抽盲按钮状态
        };
    },
    computed: {

    },
    created() {
    },
    mounted() {
      this.getYearTeam();
      this.getLists();
      this.init();
    },
    methods: {
        // 初始化方法
        init() {
          // 查询当前学生查重是否通过；
          checkRepeat(this.global.currentUser.uid).then(resp=>{
            if (resp.code === 200 && resp.data) {
              this.checkResult = resp.data.status;//查重状态
            }
          })
        },
        // 获取学年
        getYearTeam () {
          calendars.listAllCalendar().then(res => {
            if (res.code === 200) {
              let currentYear = res.data.filter(v => v.currentTermFlag)[0];
              this.yearTerms = currentYear?currentYear:{};
            }
          });
        },
        pageChange(val) { // 分页切换功能
          [this.page.pageNum_, this.page.pageSize_] = [val.pageNum, val.pageSize];
          this.getLists();
        },
        getLists() {  // 获取列表
          let params = {
            ...this.page,
            condition: {}
          };
          applyTableList(params).then(response => {
              if (response.code === 200) {
                //未抽盲时，显示默认值
                if(!response.data.thesisConcealEvaGradeT){
                  this.thesisConcealEvaGrade = {
                    selectedFlag:'UNBLIND',
                    evaCount:0,
                    evaThesisCount:0,
                    needPassCount:0,
                    passThesisCount:0,
                    finalResult:'INCOMPLETE'
                  }
                }else{
                  this.thesisConcealEvaGrade = response.data.thesisConcealEvaGradeT;
                }
                this.thesisConcealEvaGrade.midCheck = response.data.midCheck;//中期考核
                this.data = response.data.pageResult.list;
                this.total = response.data.pageResult.total_;
              } else throw response.code;
            });
        },
        add(val, type) { // 申请/详情
          if (type === 'detail') {
            this.titles = this.$t('paperBlindTrial.reviewDetail');
          }
          this.rows = _.cloneDeep(val);
          this.dialogType = type;
          this.dialogFlag = true;
        },
        sure() { // 申请确定
          if (this.rows.applyId) {
            this.$refs.paperHiddenApply.save('edit');
            return;
          }
          this.$refs.paperHiddenApply.save();
        },
        backFunc () {
          this.dialogFlag = false;
          this.getLists();
        },
        getType(val) {
          let option = this.options.applyStatus.find(v => v.value == val);
          return option ? option.type : null
        },
        //打开查重系统
        openRecheckingSystem(){
            window.open("https://lwcc.tongji.edu.cn/lw/Check/login");
        },
        // 盲抽方法
        manualRateFunc () {
          //获取查重结果
          let stuNo = this.global.currentUser.uid
          checkRepeat(stuNo).then(response=>{
            if(response.code == 200 && response.data){
              if(4 != response.data.status && 6 != response.data.status ){
                  //4-查重通过，6-查重延后，这两种情况允许抽盲
                this.$message.error(this.$t('paperBlindTrial.checkRepeatTips'));
                return;
              }
              let data = {
                thesisTitle:response.data.title ,//题目
                thesisTitleEn:response.data.enTitle,//英文题目
                thesisResearchField:response.data.researchDirection,//研究方向
                thesisKeyword:response.data.keyword//关键词
              };
              // 需要判断当前是否在开放时间内；
              applyManualRate(stuNo).then(resp=>{
                if (resp.code === 200) {
                  let param = resp.data;
                  //论文查重系统返回题目则更新论文题目否则直接抽盲
                  if(data.thesisTitle){
                    param.thesisTitle = data.thesisTitle;
                    param.thesisTitleEn = data.thesisTitleEn;
                    param.thesisResearchField = data.thesisResearchField;
                    param.thesisKeyword = data.thesisKeyword;
                    updateApply(param).then(res=>{
                      if(res.code === 200){
                        this.$message.success(this.$t('paperBlindTrial.operateSuccess'));
                        this.getLists();
                      }
                    })
                  }
                  this.$message.success(this.$t('paperBlindTrial.operateSuccess'));
                  this.getLists();
                }
              });
            }else{
                this.$message.error(this.$t('paperBlindTrial.getCheckRepeatResultTips'));
                return;
            }
          });
        },
        // 再次申请
        addNewApply() {
          let stuNo = this.global.currentUser.uid
          checkRepeat(stuNo).then(response=>{
            if(response.code == 200 && response.data){
              if(4 != response.data.status && 6 != response.data.status){
                  this.$message.error(this.$t('paperBlindTrial.againCheckRepeatTips'));
                  return;
              }else{
                  //4-查重通过，6-查重延后，这两种情况允许抽盲
                  if(6 != response.data.status && this.thesisConcealEvaGrade.updateTime && response.data.completeTime){
                      let flag = Number(moment(this.thesisConcealEvaGrade.updateTime).format('x')) >= Number(moment(response.data.completeTime).format('x'));
                      if(flag){
                          this.$message.error(this.$t('paperBlindTrial.againCheckRepeatTips'));
                          return;
                      }
                  }
              }
              let param = {};
              if(response.data.title){
                param.thesisTitle = response.data.title;
                param.thesisTitleEn = response.data.enTitle;
                param.thesisResearchField = response.data.researchDirection;
                param.thesisKeyword = response.data.keyword;
              }
              againApply(param).then(res=>{
                if (res.code === 200) {
                  this.$message.success(this.$t('paperBlindTrial.operateSuccess'));
                  this.getLists();
                }
              });
            }else{
                this.$message.error(this.$t('paperBlindTrial.getCheckRepeatResultTips'));
                return;
            }
          });
        }
  }
};
</script>

<style scoped lang="scss">
.con {
    &_content {
        display: flex;
        flex-direction: column;
    }
    &_apply {
        align-self: flex-end;
        margin-bottom: 10px;
    }
    &_status {
        border-bottom: solid #ccc 1px;
        display: block;
        padding: 5px 0;
        margin-bottom: 10px;
    }
    &_title {
      width: 100%;
      border-bottom: solid #ccc 2px;
      padding: 20px;
    }
}
.color {
  background-color: white;
}
.text-style {
  color: #2B3B4E;
}
.sub-text {
  color: #8896A7;
}
.title-left {
  text-align: center;
}
.left-sub {
  margin-top: 5px;
  font-size: 20px;
  font-weight: bold;
  color: #2B3B4E;
}
.btn_top {
  margin-top: 10px;
}
</style>
